<template>
  <el-container>
    <el-aside width="200px">
      <el-menu :default-openeds="['1']">
        <el-submenu index="1">
          <template slot="title"><i class="el-icon-news"></i>文章</template>
          <el-menu-item-group>
            <el-menu-item index="1-1">发布文章</el-menu-item>
            <el-menu-item index="1-2">管理文章</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title"><i class="el-icon-setting"></i>用户</template>
          <el-menu-item index="2-1">用户管理</el-menu-item>
          <el-menu-item index="2-2">黑名单</el-menu-item>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title"><i class="el-icon-warning"></i>客户</template>
          <el-menu-item index="2-1">留言管理</el-menu-item>
          <el-menu-item index="2-2">投资计算管理</el-menu-item>
        </el-submenu>
        <el-submenu index="4">
          <template slot="title"><i class="el-icon-warning"></i>日志</template>
          <el-menu-item index="2-1">用户管理</el-menu-item>
          <el-menu-item index="2-2">黑名单</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>查看</el-dropdown-item>
            <el-dropdown-item>新增</el-dropdown-item>
            <el-dropdown-item>删除</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>{{username}}</span>
      </el-header>
      <el-main>
        <el-table :data="articleList" style="width: 100%" :row-class-name="tableRowClassName">
          <el-table-column prop="title" label="标题"></el-table-column>
          <el-table-column prop="author" label="发布作者" ></el-table-column>
          <el-table-column prop="createTime" label="发布日期" ></el-table-column>
          <el-table-column prop="updateTime" label="修改日期" ></el-table-column>
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="prev, pager, next"
          :total="20">
        </el-pagination>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
// eslint-disable-next-line
import VueFroala from 'vue-froala-wysiwyg'

export default {
  name: 'Admin',
  data () {
    return {
      title: 'CMS后台管理',
      username: localStorage.username,
      articleList: [],
      pageIndex: 1,
      pageSize: 10,
      centerDialogVisible: false,
      dialogFullScreen: true
    }
  },
  methods: {
    tableRowClassName ({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row'
      } else if (rowIndex === 3) {
        return 'success-row'
      }
      return ''
    },
    getArticleList: function () {
      this.axios.get(getGServerUrl() + '/article/find/articles', {
        params: {
          index: this.pageIndex,
          pageSize: this.pageSize
        }
      })
        .then(response => {
          console.log(response)
          let data = response.data.data.obj
          if (data) {
            this.articleList = data
          }
        })
    },
    handleEdit: function (index, row) {
      console.log(index, row)
      this.centerDialogVisible = true
    }
  },
  mounted () {
    // this.getArticleList()
  }
}
</script>

<style scoped>
  .el-container{
    height: 100%;
  }
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
    text-align: right;
    font-size: 12px
  }
  .el-aside {
    height: 100%;
    background-color: #D3DCE6;
    color: #333;
    line-height: 200px;
  }

  .el-main {
    background-color: #E9EEF3;
    color: #333;
    line-height: 160px;
  }
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  .el-pagination{
    text-align: center;
    margin-top: 20px;
  }
</style>
